//**************************************************************************************************************
// CLASS: InstrTypeRI
//
// DESCRIPTION
// See comments in InstrTypeRI.hpp.
//
// AUTHOR INFORMATION
// Group 2
// Tyler Williams
// Lauren Walker
// Cameron Stewart
// Fatimah Alowah
//**************************************************************************************************************
#include "InstrTypeRI.hpp"

//==============================================================================================================
// PUBLIC FUNCTION MEMBERS
//==============================================================================================================

//--------------------------------------------------------------------------------------------------------------
// Default ctor.
//
// DESCRIPTION:
// Does nothing.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::InstrTypeRI(){}

InstrTypeRI::InstrTypeRI
    (
    std::string const& pMnemonic,
    Register const&       pRegister,
    Integer const&	 pInteger	
    )
    :
    InstrTypeR(pMnemonic,pRegister),
    mInteger(pInteger)
{
    Encode();
}

//--------------------------------------------------------------------------------------------------------------
// Copy ctor.
//
// DESCRIPTION:
// Calls Copy() and passess pInstr to make this object a copy of pInstr.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::InstrTypeRI
    (
    InstrTypeRI const& pInstr
    )
{
    Copy(pInstr);
}

//--------------------------------------------------------------------------------------------------------------
// Dtor.
//
// DESCRIPTION:
// Does nothing.
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI::~InstrTypeRI
    (
    )
{
}

//--------------------------------------------------------------------------------------------------------------
// Encode()
//
// DESCRIPTION:
// When an InstrTypeRI is encoded, we first call the base class InstrTypeR::Encode() function to allow it to
// place the register bit in position 26 (note that InstrTypeR::Encode() calls Instr::Encode() to allow that
// function to encode the opcode bits). Then we place the integer bits into the encoding.
//
// PSEUDOCODE:
// Call InstrTypeR::Encode()
// Put the immediate into the proper bit positions of mEncoding.
//--------------------------------------------------------------------------------------------------------------
void InstrTypeRI::Encode
    (
    )
{
    InstrTypeR::Encode();
    mEncoding |= mInteger.GetValue() << 25;  //not sure which bit position to put it in
}

//--------------------------------------------------------------------------------------------------------------
// GetInteger()
//
// DESCRIPTION:
// mInteger accessor function.
//--------------------------------------------------------------------------------------------------------------
Integer InstrTypeRI::GetInteger
    (
    )
    const
{
    return mInteger;
}


//--------------------------------------------------------------------------------------------------------------
// operator=()
//--------------------------------------------------------------------------------------------------------------
InstrTypeRI& InstrTypeRI::operator=
    (
    InstrTypeRI const& pInstr
    )
{
    if (this != &pInstr) Copy(pInstr);
    return *this;
}


//==============================================================================================================
// PROTECTED FUNCTION MEMBERS
//==============================================================================================================

//--------------------------------------------------------------------------------------------------------------
// Copy()
//
// DESCRIPTION:
// Makes this InstrTypeRI a copy of pInstr.
//
// PSEUDOCODE:
// Call the base class Copy() function and pass pInstr as the param
// Copy the mInteger data member of pInteger to this object's mInteger data member
// Call Encode() to encode the instruction
//--------------------------------------------------------------------------------------------------------------
void InstrTypeRI::Copy
    (
    InstrTypeRI const& pInstr
    )
{
    // Copy the base class (Instr) data members to 'this'.
    InstrTypeR::Copy(pInstr);                               

    // Copy the derived class (InstrTypeRI) data members to 'this'.
    SetInteger(pInstr.GetInteger());

    Encode();
}


//--------------------------------------------------------------------------------------------------------------
// SetInteger()
//
// DESCRIPTION:
// mInteger mutator function.
//--------------------------------------------------------------------------------------------------------------
void InstrTypeRI::SetInteger
    (
    Integer const& pInteger
    )
{
    mInteger = pInteger;
}


//==============================================================================================================
// PRIVATE FUNCTION MEMBERS
//==============================================================================================================
